package com.ssy.lingxi.member.merchant.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.DropdownItem;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 币别类型枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2021-05-25
 */
public enum CurrencyTypeEnum {

    /**
     * 币别枚举
     * 1: CNY-人民币
     * 2: USD-美元
     * 3: JPY-日元
     * 4: EUR-欧元
     */

    /**
     * 1: CNY-人民币
     */
    RMB(1, "CNY-人民币"),

    /**
     * 2: USD-美元
     */
    DOLLAR(2, "USD-美元"),

    /**
     * 3: JPY-日元
     */
    YEN(3, "JPY-日元"),

    /**
     * 4: EUR-欧元
     */
    euro(4, "EUR-欧元");

    CurrencyTypeEnum(Integer code, String msg) {
        this.code = code;
    }

    private final Integer code;

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    public static List<DropdownItem> toDropdownList() {
        List<DropdownItem> items = Arrays.stream(CurrencyTypeEnum.values()).sorted(Comparator.comparingInt(CurrencyTypeEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
        items.add(0 , new DropdownItem(0, MemberStringEnum.CHOOSE.getName()));
        return items;
    }

    public static List<DropdownItem> toEditableDropdownList() {
        return Arrays.stream(CurrencyTypeEnum.values()).sorted(Comparator.comparingInt(CurrencyTypeEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
    }

    public static String getCodeMsg(Integer code) {
        return LanguageHolder.getName(CurrencyTypeEnum.class, code);
    }
}
